package com.mask.juc.v1.c_006;

import java.util.concurrent.TimeUnit;

/**
 * @author hx
 * @date 2021/10/11 9:55 下午
 */

public class T {
    volatile boolean running = true; //对比一下有无volatile的情况下，整个程序运行结果的区别
    void m(){
        System.out.println("m start");
        while (running){
//            try {
//                TimeUnit.SECONDS.sleep(10);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        }
        System.out.println("m end");
    }

    public static void main(String[] args) {
        T t = new T();
        new Thread(t::m, "t1").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.running = false;
    }
}
